package com.google.code.jcooky.chat.server.client;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;

import com.google.code.jcooky.chat.commons.jrc.PacketType;

public class Client {
	private String id;
	
	private Map<PacketType, Queue<Object>> sendQ = new HashMap<PacketType, Queue<Object>>();
	
	public Client(String id) {
		this.id = id;
		
		for(PacketType key : PacketType.values()) {
			sendQ.put(key, new LinkedList<Object>());
		}
	}
	
	public String getId() {
		return id;
	}
	
	public Queue<Object> getSendQ(PacketType packetType) {
		return sendQ.get(packetType);
	}
	
	public Object remove(PacketType packetType) {
		Queue<Object> q = sendQ.get(packetType);
		
		synchronized(q) {
			return q.remove();
		}
	}
	
	public void add(PacketType packetType, Object o) {
		Queue<Object> q = sendQ.get(packetType);
		
		synchronized(q) {
			q.add(o);
		}
	}
	
	public boolean equals(Object o) {
		if(o instanceof Client) {
			return id.equals(((Client)o).id);
		}
		
		return super.equals(o);
	}
}
